package com.the_ring.behavior.memento;

/**
 * @author: t22306139
 * @date: 2023/12/1  15:06
 */
public class MainTest {

    public static void main(String[] args) {
        Caretaker caretaker = new Caretaker();
        Originator originator = new Originator();

        // 管理者使用备忘录记录状态
        originator.setState("状态1");
        caretaker.setMemento(originator.createMemento());

        originator.setState("状态2");
        caretaker.setMemento(originator.createMemento());

        // 修改原发器的状态
        originator.setState("状态3");
        System.out.println("当前合同状态：" + originator.getState());

        // 恢复备忘录中存的状态
        originator.restoreMemento(caretaker.getMemento());
        System.out.println("回退上一合同状态" + originator.getState());

        originator.restoreMemento(caretaker.getMemento());
        System.out.println("回退上一合同状态" + originator.getState());
    }
}
